//1代码创建子进程， 父进程调用wait/waitpid函数进行等待， 子进程打印“i am child process”之后，等待5s钟结束子进程；

//2 父进程在等待到子进程之后， 分析子进程的退出信号， coredump标志位以及退出码， 并打印到标准输出
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<signal.h>
int main()
{
  pid_t cpid;
  int status;
  cpid = fork();
  if(cpid == 0)
  {
    printf("I am child pid:%d\n",getpid());
    sleep(10);
    exit(0);
  }
  else if(cpid == -1)
  {
    perror("fork");
    exit(EXIT_FAILURE);
  }else 
  {
    waitpid(cpid,&status,0);
    if (WIFEXITED(status)) {
        printf("Child process exited normally with status: %d\n", WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
        printf("Child process terminated by signal: %d\n", WTERMSIG(status));
        #ifdef WCOREDUMP
            if (WCOREDUMP(status)) {
                printf("Core dumped\n");
            } else {
                printf("Core not dumped\n");
            }
        #endif
    }
  }
  return 0;
}
